/**
 * @file    Expression classname is undefined on line 2, column 15 in Templates/Classes/Class.java.
 * @author  Haseeb Yousaf
 * @see     LICENSE (MIT style license file)
 * @version 1.0
 * @date    Nov 17, 2011 4:35:04 PM
 */
package carrello.impl.controller.administrator;

import carrello.model.entitydao.CategoryDAO;
import carrello.impl.controller.AbstractCTRL;
import carrello.model.entities.Category;
import static carrello.util.EntityManagerUtil.getEntityManager;

public class UpdateCategoryCTRL extends AbstractCTRL{
    private int cid;
    private Category category;
    public UpdateCategoryCTRL(int cid)
    {
        this.cid = cid;
    }
    
    public void updateCategory(String cname, String cdesc)
    {
        
        if (verify(cid)) {
            category.setName(cname);
            category.setDescription(cdesc);
            init();
            getEntityManager().update(category);
            end();
        } // if
    } // updateCategory
    
    private boolean verify(int cid)
    {
        category = new CategoryDAO().getById(cid);
        return (category == null)? false : true;
    }
            
    
} // UpdateCategoryCTRL
